﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RxxApi.Common.Helper;
using RxxApi.Extensions.Authorizations;
using RxxApi.Extensions.Cache;
using RxxApi.Model;
using Serilog;
using SqlSugar;
using ICacheService = RxxApi.Extensions.Cache.ICacheService;

namespace RxxApi.Api.Controllers
{
    /// <summary>
    /// 测试
    /// </summary>
    public class TestController : BaseApiController
    {
        private readonly ICacheService _cacheService;
        public TestController(ICacheService cacheService)
        {
            _cacheService = cacheService;
        }
        /// <summary>
        /// 测试获取配置信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string GetConfigure() {
            string a = AppSettings.Startup.ApiName;
            string[] b = AppSettings.AllowCors;
            string c = AppSettings.app("Startup:ApiName");
            List<object> d = AppSettings.app<object>("Startup:a");
            string e = AppSettings.GetValue("Startup:aa:bb");
            return a + " " +  b + " " + c + " " + d + " " + e;
        }
        /// <summary>
        /// 测试Serilog日志
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string GetSerilog() {
            Log.Information("111");
            return "";
        }
        /// <summary>
        /// 测试成功返回统一格式
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public MessageModel GetMessageModel()
        {           
            return Success("Hello World");
        }
        /// <summary>
        /// 获取Token
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<MessageModel> GetToken()
        {
            await Task.CompletedTask;
            string jwtStr = string.Empty;
            //TokenModelJwt tokenModel = new TokenModelJwt { Uid = 1 };
            //jwtStr = JwtHelper.IssueJwt(tokenModel);
            //jwtStr = JwtHelper.CreateToken("1", "2");
            return Success(jwtStr);
        }
        /// <summary>
        /// 测试缓存
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        [HttpPost]
        public string GetCache(string val) {
            //测试Redis缓存
            _cacheService.Add("rxx", val);
            return _cacheService.Get("rxx").ToString();
        }
    }
}
